package com.jzqf.harmonydemo.library.camera;

import com.jzqf.harmonydemo.utils.LogUtil;
import ohos.agp.components.AttrSet;
import ohos.agp.components.surfaceprovider.SurfaceProvider;
import ohos.app.Context;

/**
 * 相机预览
 *
 * @author LiuWeiHao
 * 2021/5/24 10:51
 */
public class SurfaceProviderPreview extends SurfaceProvider {
    private int mRatioWidth = 0;
    private int mRatioHeight = 0;

    public SurfaceProviderPreview(Context context) {
        super(context);
        init();
    }

    public SurfaceProviderPreview(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init();
    }

    public SurfaceProviderPreview(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init();
    }

    private void init() {

    }

    public void setAspectRatio(int srcWidht, int srcHeight) {
        //1080x2340
        this.mRatioWidth = srcHeight;
        this.mRatioHeight = srcWidht;
        //3:4画面
        int estimateWidth = (getHeight() * mRatioWidth) / mRatioHeight;
        int estimateHeight = (getWidth() * mRatioHeight) / mRatioWidth;
        //1080x1920   1270x2259  9:16
//        if (estimateWidth > getWidth()) {
//
//        } else {
//            setHeight(estimateWidth);
//        }
        setWidth(1270);
        setHeight(2259);
        LogUtil.d("camera", "width=" + getWidth() + ",height=" + getHeight());
        LogUtil.d("camera", "mRatioWidth=" + mRatioWidth + ",mRatioHeight=" + mRatioHeight);
        LogUtil.d("camera", "estimateWidth=" + estimateWidth + ",estimateHeight=" + estimateHeight);
    }

}
